package com.amsp.oa.oademo.service.impl;

import com.amsp.oa.oademo.entity.PerformanceBonusBase;
import com.amsp.oa.oademo.mapper.PerformanceBonusBaseMapper;
import com.amsp.oa.oademo.service.PerformanceBonusBaseService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class PerformanceBonusBaseServiceImpl implements PerformanceBonusBaseService {

    @Autowired
    private PerformanceBonusBaseMapper bonusBaseMapper;

    @Override
    public PerformanceBonusBase getById(Long id) {
        return bonusBaseMapper.selectById(id);
    }

    @Override
    public IPage<PerformanceBonusBase> getPage(Integer current, Integer size, String employeeId, String name) {
        Page<PerformanceBonusBase> page = new Page<>(current, size);
        LambdaQueryWrapper<PerformanceBonusBase> wrapper = new LambdaQueryWrapper<>();
        
        wrapper.like(StringUtils.hasText(employeeId), PerformanceBonusBase::getEmployeeId, employeeId)
               .like(StringUtils.hasText(name), PerformanceBonusBase::getName, name)
               .orderByDesc(PerformanceBonusBase::getCreateTime);
        
        return bonusBaseMapper.selectPage(page, wrapper);
    }

    @Override
    public boolean saveOrUpdate(PerformanceBonusBase entity) {
        if (entity.getId() == null) {
            return bonusBaseMapper.insert(entity) > 0;
        }
        return bonusBaseMapper.updateById(entity) > 0;
    }

    @Override
    public boolean removeById(Long id) {
        return bonusBaseMapper.deleteById(id) > 0;
    }
} 